package com.ksd.dao.impl;

import com.ksd.dao.IMeetingDAO;
import com.ksd.pojo.Meeting;
import org.hibernate.SessionFactory;

import java.util.List;

public class MeetingDAO implements IMeetingDAO {

    private SessionFactory sessionFactory;

    public void setSessionFactory(SessionFactory sessionFactory) {
        this.sessionFactory = sessionFactory;
    }


    /**
     * when have pageSize and pageNo parameters
     */
    public List findAll() {
        return sessionFactory.getCurrentSession().createQuery("from Meeting").list();
    }

    public Meeting findById(String id) {
        return (Meeting) sessionFactory.getCurrentSession().get(Meeting.class,
                new Integer(id));
    }

    public void insert(Meeting meeting) {
        sessionFactory.getCurrentSession().save(meeting);
    }

    public void update(Meeting meeting) {
        sessionFactory.getCurrentSession().update(meeting);
    }

    public void delete(String id) {
        Object p = sessionFactory.getCurrentSession().load(Meeting.class, new Integer(id));
        sessionFactory.getCurrentSession().delete(p);
    }

}
